package com.situ.web.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.situ.web.entity.PageBean;
import com.situ.web.entity.User;
import com.situ.web.service.IStudentService;
import com.situ.web.service.impl.StudentServiceImpl;

public class PageListStudentServlet extends HttpServlet{
	private IStudentService studentService = new StudentServiceImpl();

	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		System.out.println("PageListStudentServlet.service()");
		//判断用户有没有登录
		/*HttpSession session = req.getSession();
		User user = (User) session.getAttribute("user");
		if (user == null) {
			//用户没有登录，重定向到登录界面
			resp.sendRedirect(req.getContextPath() + "/login.jsp");
			return;
		}*/
		//http://localhost:8080/Java1812Web/pageList?pageNo=5&pageSize=3
		//1.得到请求参数
		String pageNoStr = req.getParameter("pageNo");
		/*int pageNo = 0;
		if (pageNoStr == null) {
			pageNo = 1;
		} else {
			pageNo = Integer.parseInt(req.getParameter("pageNo"));
		}*/
		int pageNo = (pageNoStr == null) ? 1 : Integer.parseInt(pageNoStr);
		
		String pageSizeStr = req.getParameter("pageSize");
		int pageSize = (pageSizeStr == null) ? 3 : Integer.parseInt(pageSizeStr);
		
		//2.调用service层业务逻辑，得到封装好的PageBean返回给jsp界面展示
		PageBean pageBean = studentService.getPageBean(pageNo, pageSize);
		System.out.println(pageBean);
		//3.转发到列表界面展示
		req.setAttribute("pageBean", pageBean);
		req.getRequestDispatcher("/student_page_list.jsp").forward(req, resp);
	}
	
	public static void main(String[] args) {
		String str = null;
		int num = Integer.parseInt(str);
		System.out.println(num);
	}
}
